<?php

/**
 * Subclass for performing query and update operations on the 'list_countries' table.
 *
 * 
 *
 * @package lib.model
 */ 
class ListCountriesPeer extends BaseListCountriesPeer
{

  public static function doSelectSortByName(){
    $c = new Criteria();
    $c->addAscendingOrderByColumn(self::NAME);
    return self::doSelect($c);
  }

  public static function getList(){
    $c = new Criteria();
    $c->addAscendingOrderByColumn(self::NAME);
    $countrys = self::doSelect($c);
    $data = array();
    foreach($countrys as $country){
      $data[$country->getName()] = $country->getName();
    }
    return $data;
  }
 
  public static function getListWithBlank(){
    $c = new Criteria();
    $c->addAscendingOrderByColumn(self::NAME);
    $countrys = self::doSelect($c);
    $data = array(''=>'');
    foreach($countrys as $country){
      $data[$country->getName()] = $country->getName();
    }
    return $data;
  }
  
  
  public static function getCurrencyCodeList(){
    $c = new Criteria();
    $c->addAscendingOrderByColumn(self::CURRENCY_CODE);
    $countrys = self::doSelect($c);
    $data = array(''=>'');
    foreach($countrys as $country){
      $data[$country->getCurrencyCode()] = $country->getCurrencyCode();
    }
    return $data;
  }

  
  public static function getJsonCurrencyCodeList(){
    $c = new Criteria();
    $c->addAscendingOrderByColumn(self::CURRENCY_CODE);
    $countrys = self::doSelect($c);
    $data = array();
    foreach($countrys as $country){
      $data[] = array($country->getCurrencyCode());
    }
    return json_encode($data);
  }

  
  public static function getJsonCountryList(){
    $c = new Criteria();
    $c->addAscendingOrderByColumn(self::NAME);
    $countrys = self::doSelect($c);
    $data = array();
    foreach($countrys as $country){
      $data[] = array($country->getName());
    }
    return json_encode($data);
  }
  
  
  
  
  public static function setDefault($iden){
    $countrys = self::doSelect(new Criteria());
    foreach ($countrys as $country){
      $country->setIsDefault('N');
      $country->save();
    }
    $country = self::retrieveByPk($iden);
    if($country){
      $country->setIsDefault('Y');
      $country->save();
    }
  }
  
  public static function getDefaultCountryName(){
    $c = new Criteria();
    $c->add(self::IS_DEFAULT,'Y');
    $country = self::doSelectOne($c);
    if($country)
      return $country->getName();
    else
      return '';
  }
  
  public static function getDefaultCurrencyCode(){
    $c = new Criteria();
    $c->add(self::IS_DEFAULT,'Y');
    $country = self::doSelectOne($c);
    if($country)
      return $country->getCurrencyCode();
    else
      return '';
  }
  
}
